<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>超市账单管理系统</title>
    <link rel="stylesheet" href="/static/css/public.css"/>
    <link rel="stylesheet" href="/static/css/style.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery.js"></script>
    <script type="text/javascript">
        $(function () {
            //用户查看按钮单击事件
            $("a[name='query']").click(function () {
                //ajax获取用户对象信息
                var id=$(this).attr("proId");
                //ajax异步方法
               /* $.get("/sys/provider/queryById","id="+id,function (result) {
                    //加载数据
                    $("#proCode").html(result.proCode);
                    $("#proName").html(result.proName);
                    $("#proContact").html(result.proContact);
                    $("#proPhone").html(result.proPhone);
                    $("#proFax").html(result.proFax);
                    $("#proDesc").html(result.proDesc);
                    //显示div
                    $("#providerDiv").show();
                });*/
               //同步方法
                location.href="/sys/provider/queryById2?id="+id;
            });
            //删除供应商
            $("a[name='delete']").click(function () {
                //获取供应商id
                var id = $(this).attr("proId");
                //获取供应商的名称
                var name = $(this).attr("proName")
                if(confirm("确定要删除【"+name+"】供应商吗？")){
                    $.get("/sys/provider/delete","id="+id,function (result) {
                        if (result=='success'){
                            alert("删除成功");
                            //刷新当前页
                            location.href = location.href;
                        }else{
                            alert("删除失败，请稍后再试");
                        }
                    })
                }
            });
            //修改供应商信息按钮单击事件
            $("a[name='update']").click(function () {
                //获取供应商id
                var id = $(this).attr("proId");
                location.href="/sys/provider/toUpdate?id="+id;
            })
        });
    </script>
</head>
<body>
<section class="publicMian ">
    <div class="right" style="width: 100%">
        <div class="location">
            <strong>你现在所在的位置是:</strong>
            <span>供应商管理页面</span>
        </div>
        <div class="search">
            <form id="searchForm">
                <span>供应商编码：</span>
                <input type="text" name="proCode" value="${provider.proCode}" placeholder="请输入供应商编码">
                <span>供应商名称：</span>
                <input type="text" name="proName" value="${provider.proName}" placeholder="请输入供应商的名称"/>
                <input type="button" value="查询" id="searchButton"/>
                <a href="/sys/provider/toSave">添加供应商</a>
            </form>

        </div>
        <!--供应商操作表格-->
        <table class="providerTable" cellpadding="0" cellspacing="0">
            <tr class="firstTr">
                <th width="10%">供应商编码</th>
                <th width="20%">供应商名称</th>
                <th width="10%">联系人</th>
                <th width="10%">联系电话</th>
                <th width="10%">传真</th>
                <th width="10%">创建时间</th>
                <th width="30%">操作</th>
            </tr>
           <c:forEach items="${pageInfo.list}" var="pro">
            <tr>
                <td>${pro.proCode}</td>
                <td>${pro.proName}</td>
                <td>${pro.proContact}</td>
                <td>${pro.proPhone}</td>
                <td>${pro.proFax}</td>
                <td>
                        <fmt:formatDate value="${pro.creationDate}" pattern="yyyy-MM-dd"/>
                        </td>
                <td>
                    <a name="query" proId="${pro.id}"><img src="/static/img/read.png" alt="查看" title="查看"/></a>
                    <a name="update" proId="${pro.id}"><img src="/static/img/xiugai.png" alt="修改" title="修改"/></a>
                    <a name="delete" proId="${pro.id}" proName="${pro.proName}"><img src="/static/img/schu.png" alt="删除" title="删除"/></a>
                </td>
            </tr>
           </c:forEach>
        </table>
        <!--引用分页页面-->
        <jsp:include page="page.jsp"></jsp:include>
        <div class="providerView" id="providerDiv" style="display: none">
            <p><strong>供应商编号：</strong><span id="proCode"></span></p>
            <p><strong>供应商名称：</strong><span id="proName"></span></p>
            <p><strong>联系人：</strong><span id="proContact"></span></p>
            <p><strong>用户电话：</strong><span id="proPhone"></span></p>
            <p><strong>传真：</strong><span id="proFax"></span></p>
            <p><strong>描述：</strong><span id="proDesc"></span></p>
        </div>
    </div>
</section>
</body>
</html>
